package cn.edu.zut.hhr.controller;


import cn.edu.zut.hhr.annotation.CacheAnnotation;
import cn.edu.zut.hhr.annotation.LogAnnotation;
import cn.edu.zut.hhr.service.CommentService;
import cn.edu.zut.hhr.vo.RestResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author HHR
 * @since 2021-08-25
 */
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Resource
    CommentService commentService;

    @GetMapping("/article/{aid}/{page}/{pageSize}/{sonPage}/{sonPageSize}")
    @LogAnnotation(module = "评论", operator = "获取指定文章评论")
    @CacheAnnotation
    public RestResponse getCommentByAid(
            @PathVariable("aid") Long aid,
            @PathVariable("page") Integer page,
            @PathVariable("pageSize") Integer pageSize,
            @PathVariable("sonPage") Integer sonPage,
            @PathVariable("sonPageSize") Integer sonPageSize
    ){
        return commentService.getCommentByAid(aid,page,pageSize,sonPage,sonPageSize);
    }

    @PostMapping("/create")
    @LogAnnotation(module = "评论",operator = "添加评论")
    public RestResponse addComment(
            @RequestParam("aid") Long aid,
            @RequestParam("content") String content,
            @RequestParam(value = "pid",required = false) Long pid,
            @RequestParam(value = "toUid",required = false) Long toUid){
        return commentService.addComment(aid,content,pid,toUid);
    }



}
